//
//  YWEquipmentAndGreenPointTableViewCell.m
//  maintain
//
//  Created by 烟雨云渊 on 16/10/24.
//  Copyright © 2016年 ewin. All rights reserved.
//

#import "YWEquipmentAndGreenPointTableViewCell.h"
#import "YWMacro.h"
#import "Masonry.h"
#import "UIColor+CustomColors.h"
#import "YYLabel.h"

@interface YWEquipmentAndGreenPointTableViewCell()
/* 绿点 */
@property (nonatomic, strong) YYLabel * greenPointLabel;
/* 设备名 */
@property (nonatomic, strong) YYLabel * equipmentNameLabel;
/* 地址 */
@property (nonatomic, strong) YYLabel * locationLabel;
@end

@implementation YWEquipmentAndGreenPointTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.layer.shouldRasterize = YES;
        self.layer.rasterizationScale = [UIScreen mainScreen].scale;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.accessoryType = UITableViewCellAccessoryNone;
        [self setUpSubviews];
    }
    return self;
}

- (void)setEquitmentName:(NSString *)equitmentName{
    _equitmentName = equitmentName;
    self.equipmentNameLabel.text = _equitmentName;
}

- (void)setLocationString:(NSString *)locationString{
    _locationString = locationString;
    self.locationLabel.text = _locationString;
}

- (void)setUpSubviews{
    //设备名
    [self.equipmentNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).offset(10);
        make.left.mas_equalTo(self.greenPointLabel.mas_right).offset(10);
        make.right.mas_equalTo(self.contentView).offset(-10);
    }];
    //绿色点
    [self.greenPointLabel mas_makeConstraints:^(MASConstraintMaker* make) {
        make.centerY.mas_equalTo(self.equipmentNameLabel.mas_centerY);
        make.left.mas_equalTo(self.contentView.mas_left).offset(10);
        make.width.mas_equalTo(14);
        make.height.mas_equalTo(14);
    }];
    //位置
    [self.locationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.equipmentNameLabel.mas_bottom).offset(10);
        make.left.mas_equalTo(self.contentView).offset(10);
        make.right.mas_equalTo(self.contentView).offset(-10);
        make.bottom.mas_equalTo(self.contentView).offset(-10);
    }];
}

- (YYLabel *)greenPointLabel{
    if (!_greenPointLabel) {
        YYLabel *label = [[YYLabel alloc] init];
        label.backgroundColor = [UIColor customGreenColor];
        label.layer.masksToBounds = YES;
        label.layer.cornerRadius = 14/2;
        _greenPointLabel = label;
        [self.contentView addSubview:_greenPointLabel];
    }
    return _greenPointLabel;
}

- (YYLabel *)equipmentNameLabel{
    if (!_equipmentNameLabel) {
        YYLabel *label = [[YYLabel alloc] init];
        label.font = KSmallContentFont;
        label.textColor = [UIColor blackColor];
        _equipmentNameLabel = label;
        [self.contentView addSubview:_equipmentNameLabel];
    }
    return _equipmentNameLabel;
}

- (YYLabel *)locationLabel{
    if (!_locationLabel) {
        YYLabel *label = [[YYLabel alloc] init];
        label.font = KSmallContentFont;
        label.textColor = [UIColor customTextGrayColor];
        _locationLabel = label;
        [self.contentView addSubview:_locationLabel];
    }
    return _locationLabel;
}

@end
